﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing;

namespace WINBASE.Controls
{
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
    [DefaultProperty("Items")]
    public partial class WLCTspCombo : WLCToolStripControlHost 
    {
        #region Constructor & Load

        public WLCTspCombo() : base(CreateControlInstance())
        {
            WLCCombobox combo = Control as WLCCombobox;
        }

        public WLCTspCombo(IContainer container) : base(CreateControlInstance())
        {
            container.Add(this);
        }

        public WLCTspCombo(string name) : this()
        {
            this.Name = name;
        } 

        #endregion

        #region Method

        private static Control CreateControlInstance()
        {
            WLCCombobox myCbo = new WLCCombobox();
            myCbo.DropDownStyle = ComboBoxStyle.DropDownList;
            myCbo.FlatStyle = FlatStyle.Flat;
            myCbo.Font = new Font(ApplicationData.AppFont.FontFamily, 8);
            return myCbo;
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);
            WLCCombobox cb = control as WLCCombobox;

            if (cb != null)
            {
                cb.SelectedIndexChanged += new EventHandler(OnSelectedChanged);
            }
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnUnsubscribeControlEvents(control);
            WLCCombobox cb = control as WLCCombobox;

            if (cb != null)
            {
                cb.SelectedIndexChanged -= OnSelectedChanged;
            }
        }

        private void OnSelectedChanged(object sender, EventArgs e)
        {
            if (SelectedChanged != null)
            {
                SelectedChanged(sender, e);
            }
        }

        #endregion

        #region Property

        public ComboBox.ObjectCollection Items
        {
            get { return ((ComboBox)Control).Items; }
        }

        public object DataSource
        {
            get { return ((ComboBox)Control).DataSource; }
            set { ((ComboBox)Control).DataSource = value; }
        }

        public string DisplayMember
        {
            get { return ((ComboBox)Control).DisplayMember; }
            set { ((ComboBox)Control).DisplayMember = value; }
        }

        public string ValueMember
        {
            get { return ((ComboBox)Control).ValueMember; }
            set { ((ComboBox)Control).ValueMember = value; }
        }

        public int SelectedIndex
        {
            get { return ((ComboBox)Control).SelectedIndex; }
            set { ((ComboBox)Control).SelectedIndex = value; }
        }

        #endregion

        public event EventHandler SelectedChanged;

    }
}
